<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .active1 {
        width: 100vw;
        height: 100vh;
        background: url(images/1.png) no-repeat top left/contain;
      }
      .active2 {
        width: 100vw;
        height: 100vh;
        background: url(images/2.png) no-repeat top left/contain;
      }
    </style>
  </head>
  <body>
    <button>点击设置背景1</button>
    <button>点击设置背景2</button>
    <script>
      var btns = document.querySelectorAll("button");

      Array.from(btns).forEach(function (item, i, arr) {
        item.onclick = function () {
          if (i == 0) {
            document.body.className = "active1";
          }
          if (i == 1) {
            document.body.className = "active2";
          }
        };
      });
    </script>
  </body>
</html>
